class DoorStateMachine {
    constructor() {
        this.state = 'closed'; // 初始状态设为“关闭”
    }

    open() {
        if (this.state === 'closed') {
            this.state = 'open';
            console.log('门已打开');
        } else {
            console.log('门已经是打开的');
        }
    }

    close() {
        if (this.state === 'open') {
            this.state = 'closed';
            console.log('门已关闭');
        } else {
            console.log('门已经是关闭的');
        }
    }

    getState() {
        return this.state;
    }
}

// 使用示例
const door = new DoorStateMachine();
door.open();    // 输出: 门已打开
door.close();   // 输出: 门已关闭